package org.paradise.dms.util;

import message.sms.DELIVER;

import org.apache.log4j.Logger;
import org.paradise.dms.dao.impl.DeliverStationDaoImpl;
import org.paradise.dms.pojo.BaseException;
import org.paradise.dms.pojo.DeliverStation;

import com.dheaven.framework.dao.DaoException;

import common.ComFun;



@SuppressWarnings("unchecked")
public class FindDeliverSms1 extends Thread {
	private static Logger logger = Logger.getLogger(FindDeliverSms1.class);
	
    
	private DeliverStation deliverStation;
	
	public DeliverStation getDeliverStation() {
		return deliverStation;
	}


	public void setDeliverStation(DeliverStation deliverStation) {
		this.deliverStation = deliverStation;
	}


	public void run() {
		DELIVER deliver = new DELIVER();
		while (true) {
			if ((deliver = ComFun.getSMS()) != null) {
				if (deliver.getMsgFlag() == 1) {
					
					logger.info("-状态报告: " 
							+ "MAS下行消息ID ["	+ deliver.getMsgContent() + "]+" 
							+ "短信接收情况描述 ["+ deliver.getReserve() + "]+" 
							+ "下行状态 ["+ deliver.getReportState() + "]\n");
					DeliverStation deliverStation = new DeliverStation();
					deliverStation.setMsgContent(deliver.getMsgContent());
					deliverStation.setReportState(String.valueOf(deliver.getReportState()));
					
					DeliverStationDaoImpl deliverStationDao = new DeliverStationDaoImpl();
					
					try {
						deliverStationDao.add(deliverStation);
					} catch (BaseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					} else {
					
					logger.info("-上行短信：" + "上行源号码 [" + deliver.getSrcID()
							+ "]+" + "上行目的号码 [" + deliver.getDestID() + "]+"
							+ "上行消息内容 [" + deliver.getMsgContent() + "]\n");
				}

			} else {
				try {
					Thread.sleep(1000);
				} catch (Exception e) {
					logger.error(e);
				}
			}
		}
	}
}
